package com.five.service.Impl;

import com.five.dao.ClubJoinDao;
import com.five.pojo.ClubJoin;
import com.five.pojo.PageBean;
import com.five.service.ClubJoinService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClubJoinServiceImpl implements ClubJoinService {

    @Autowired
    ClubJoinDao clubJoinDao;

    //申请入团
    @Override
    public void addClub(ClubJoin clubJoin) {
        clubJoin.setCJoinTime(LocalDateTime.now());
        clubJoin.setStatus(0);
        clubJoinDao.add(clubJoin);
    }

    //查询入团申请信息
    @Override
    public List<ClubJoin> getAllJoin() {
        List<ClubJoin> list = clubJoinDao.getAllJoin();
        return list;
    }

    //分页
    @Override
    public PageBean page(Integer page, Integer pageSize , String cName , String sName) {
        PageHelper.startPage(page , pageSize);
        List<ClubJoin> clubJoinList = clubJoinDao.list(cName , sName);
        Page<ClubJoin> p = (Page<ClubJoin>) clubJoinList;
        PageBean pageBean = new PageBean(p.getTotal() , p.getResult());
        return pageBean;
    }

    @Override
    public Integer getStatus() {

        Integer total = clubJoinDao.getStatus();
        return total;
    }

    @Override
    public void updateStatus(Integer status, Integer id) {
        clubJoinDao.updateStatus(status , id);
    }

    @Override
    public List<ClubJoin> getByHeader(String header) {
        List<ClubJoin> list = clubJoinDao.getByHeader(header);
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        clubJoinDao.deleteById(id);
    }
}
